<template>
   <div>
    <!-- 给子组件传入title，color，bgc的值 -->
    <MyHeader title="购物车案例" color='yellow' bgc='green'></MyHeader>
    <div class="main">
      <!-- 循环数组，将数组中的每一项传给子组件 -->
      <MyGoods v-for="obj in list" :key="obj.id" :obj='obj'></MyGoods>
    </div>
    <!-- 将数组传给子组件 -->
    <MyFooter :list='list'></MyFooter>
  </div>
</template>

<script>
import MyHeader from './components/MyHeader'
import MyGoods from './components/MyGoods'
import MyFooter from './components/MyFooter'
export default {
  components: {
    MyHeader,
    MyGoods,
    MyFooter
  },
  data () {
    return {
      list:[]
    }
  },
  created(){
    // 发起axios请求获取数据
    this.$axios({
      url:'/api/cart'
    }).then(res=>{
      // 将数据赋值给数组
      this.list = res.data.list
    }).catch(err=>{console.log(err);})
  }
}
</script>

<style>
  .main{
    padding-top: 45px;
    padding-bottom: 50px;
  }
</style>